package com.study.example.gameserver.admin.recharge.domain;

import com.study.example.gameserver.module.currency.domain.CurrencyType;
import com.study.example.gameserver.module.currency.entity.PlayerCurrency;
import com.study.example.gameserver.module.player.domain.PlayerDataType;
import com.study.example.gameserver.module.player.entity.Player;

/**
 * 充值类型定义
 * 用于区分充值来源或发货逻辑（如普通充值、月卡、活动礼包等）
 */
public enum RechargePayType {

    NORMAL(1, "普通充值") {
        @Override
        public void reward(Player player, int money, RechargeExtData rechargeExtData) {
            int diamond = money * 10;
            PlayerCurrency playerCurrency = player.getData(PlayerDataType.Currency);
            playerCurrency.addCurrency(CurrencyType.DIAMOND, diamond);
        }
    },

    MONTH_CARD(2, "月卡充值") {
        @Override
        public void reward(Player player, int money, RechargeExtData rechargeExtData) {
            int diamond = money * 10;
            PlayerCurrency playerCurrency = player.getData(PlayerDataType.Currency);
            playerCurrency.addCurrency(CurrencyType.DIAMOND, diamond);
        }
    },

    COMPENSATION(99, "补偿发放") {
        @Override
        public void reward(Player player, int money, RechargeExtData rechargeExtData) {
            int diamond = money * 10;
            PlayerCurrency playerCurrency = player.getData(PlayerDataType.Currency);
            playerCurrency.addCurrency(CurrencyType.DIAMOND, diamond);
        }
    };

    private final int code;
    private final String desc;

    RechargePayType(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据code获取对应的类型
     */
    public static RechargePayType of(int code) {
        for (RechargePayType type : values()) {
            if (type.code == code) {
                return type;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return code + ":" + desc;
    }

    /**
     * 发货 相当于奖励
     * @param player
     * @param money
     * @param rechargeExtData
     */
    public abstract void reward(Player player, int money, RechargeExtData rechargeExtData);
}
